<!--
 * @Descripttion: (/GbPointInfo)
 * @version: (1.0)
 * @Author: (admin)
 * @Date: (2025-09-11)
 * @LastEditors: (admin)
 * @LastEditTime: (2025-09-11)
-->
<template>
  <div class="app-container">
    <!-- :model属性用于表单验证使用 比如下面的el-form-item 的 prop属性用于对表单值进行验证操作 -->
    <el-form :model="queryParams" size="small" label-position="right" inline ref="queryForm" :label-width="labelWidth"
      v-show="showSearch" @submit.native.prevent>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <!-- 工具区域 -->
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" v-hasPermi="['gbpointinfo:add']" plain icon="el-icon-plus" size="mini"
          @click="handleAdd">新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="success" :disabled="single" v-hasPermi="['gbpointinfo:edit']" plain icon="el-icon-edit"
          size="mini" @click="handleUpdate">修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="danger" :disabled="multiple" v-hasPermi="['gbpointinfo:delete']" plain icon="el-icon-delete"
          size="mini" @click="handleDelete">删除</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <!-- 数据区域 -->
    <el-table :data="dataList" v-loading="loading" ref="table" border highlight-current-row @sort-change="sortChange"
      @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="50" align="center" />
      <el-table-column prop="cdLaction" label="测点位置" align="center" :show-overflow-tooltip="true" />
      <el-table-column prop="cdBracketno" label="支架编号" align="center" />
      <el-table-column prop="cdBracketname" label="支架名称" align="center" :show-overflow-tooltip="true" />
      <el-table-column prop="cdTd" label="测点通道" align="center" :show-overflow-tooltip="true" />
      <el-table-column prop="cdFz" label="测点分站" align="center" :show-overflow-tooltip="true" />
      <el-table-column prop="cdSensor" label="测点传感器" align="center" :show-overflow-tooltip="true" />
      <el-table-column prop="cdBcsx1" label="测点波长1上限" align="center" :show-overflow-tooltip="true" />
      <el-table-column prop="cdBcsx2" label="测点波长2上限" align="center" :show-overflow-tooltip="true" />
      <el-table-column prop="cdBcsx3" label="测点波长3上限" align="center" :show-overflow-tooltip="true" />
      <el-table-column prop="cdBcsx4" label="测点波长4上限" align="center" :show-overflow-tooltip="true" />
      <el-table-column prop="cdBcxx1" label="测点波长1下限" align="center" :show-overflow-tooltip="true" />
      <el-table-column prop="cdBcxx2" label="测点波长2下限" align="center" :show-overflow-tooltip="true" />
      <el-table-column prop="cdBcxx3" label="测点波长3下限" align="center" :show-overflow-tooltip="true" />
      <el-table-column prop="cdBcxx4" label="测点波长4下限" align="center" :show-overflow-tooltip="true" />
      <el-table-column prop="cdBj" label="测点报警" align="center" :show-overflow-tooltip="true" />
      <el-table-column prop="cdYj" label="测点预警" align="center" :show-overflow-tooltip="true" />

      <el-table-column label="操作" align="center" width="140">
        <template slot-scope="scope">
          <el-button size="mini"  type="text" icon="el-icon-edit" title="编辑"
            @click="handleUpdate(scope.row)">编辑</el-button>
          <el-button size="mini"  type="text" icon="el-icon-delete" title="删除"
            @click="handleDelete(scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination class="mt10" background :total="total" :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize" @pagination="getList" />

    <!-- 添加或修改对话框 -->
    <el-dialog :title="title" :lock-scroll="false" :visible.sync="open" width="700px">
      <el-form ref="form" :model="form" :rules="rules" :label-width="formLabelWidth">
        <el-row>
          <el-col :span="24">
            <el-form-item label="测点位置" prop="cdLaction">
              <el-input v-model="form.cdLaction" placeholder="请输入测点位置" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="支架编号" prop="cdBracketno">
              <el-input v-model="form.cdBracketno" placeholder="请输入支架编号" />
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="支架名称" prop="cdBracketname">
              <el-input v-model="form.cdBracketname" placeholder="请输入支架名称" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="测点分站" prop="cdFz">
              <el-select v-model="form.cdFz" placeholder="请选择">
                <el-option v-for="item in cdFzoptions" :key="item.value" :label="item.label" :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="测点通道" prop="cdTd">
              <el-select v-model="form.cdTd" placeholder="请选择">
                <el-option v-for="item in cdTdoptions" :key="item.value" :label="item.label" :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="传感器编号" prop="cdSensor">
              <el-select v-model="form.cdSensor" placeholder="请选择">
                <el-option v-for="item in cdSensoroptions" :key="item.value" :label="item.label" :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="传感器类型" prop="cdSensorType">
              <el-input v-model="form.cdSensorType" placeholder="请输入传感器类型" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="出厂波长1" prop="cdBcsx1">
              <el-input v-model="form.cdBcsx1" placeholder="请输入出厂波长3" />
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="出厂波长2" prop="cdBcsx2">
              <el-input v-model="form.cdBcsx2" placeholder="请输入出厂波长3" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="出厂波长3" prop="cdBcsx3">
              <el-input v-model="form.cdBcsx3" placeholder="请输入出厂波长3" />
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="出厂波长4" prop="cdBcsx4">
              <el-input v-model="form.cdBcsx4" placeholder="请输入出厂波长4" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="测点波长1上限" prop="cdBcsx1">
              <el-input v-model="form.cdBcsx1" placeholder="请输入测点波长1上限" />
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="测点波长2上限" prop="cdBcsx2">
              <el-input v-model="form.cdBcsx2" placeholder="请输入测点波长2上限" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="测点波长3上限" prop="cdBcsx3">
              <el-input v-model="form.cdBcsx3" placeholder="请输入测点波长3上限" />
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="测点波长4上限" prop="cdBcsx4">
              <el-input v-model="form.cdBcsx4" placeholder="请输入测点波长4上限" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="测点波长1下限" prop="cdBcxx1">
              <el-input v-model="form.cdBcxx1" placeholder="请输入测点波长1下限" />
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="测点波长2下限" prop="cdBcxx2">
              <el-input v-model="form.cdBcxx2" placeholder="请输入测点波长2下限" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="测点波长3下限" prop="cdBcxx3">
              <el-input v-model="form.cdBcxx3" placeholder="请输入测点波长3下限" />
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="测点波长4下限" prop="cdBcxx4">
              <el-input v-model="form.cdBcxx4" placeholder="请输入测点波长4下限" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="测点报警" prop="cdBj">
              <el-input v-model="form.cdBj" placeholder="请输入测点报警" />
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="测点预警" prop="cdYj">
              <el-input v-model="form.cdYj" placeholder="请输入测点预警" />
            </el-form-item>
          </el-col>

        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="text" @click="cancel">取 消</el-button>
        <el-button type="primary" @click="submitForm">确 定</el-button>
      </div>
    </el-dialog>

  </div>
</template>
<script>
import {
  listGbPointInfo,
  addGbPointInfo,
  delGbPointInfo,
  updateGbPointInfo,
  getGbPointInfo,
} from '@/api/gb/gbPointInfo.js';

export default {
  name: "gbpointinfo",
  data() {
    return {
      labelWidth: "100px",
      formLabelWidth: "130px",
      cdFzoptions: [],
      cdTdoptions: [],
      cdSensoroptions: [],
      // 选中id数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 遮罩层
      loading: false,
      // 显示搜索条件
      showSearch: true,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        sort: undefined,
        sortType: undefined,
      },
      // 弹出层标题
      title: "",
      // 操作类型 1、add 2、edit
      opertype: 0,
      // 是否显示弹出层
      open: false,
      // 表单参数
      form: {},
      columns: [
        { index: 0, key: 'id', label: `Id`, checked: true },
        { index: 1, key: 'cdLaction', label: `测点位置`, checked: true },
        { index: 2, key: 'cdBracketno', label: `支架编号`, checked: true },
        { index: 3, key: 'cdBracketname', label: `支架名称`, checked: true },
        { index: 4, key: 'cdTd', label: `测点通道`, checked: true },
        { index: 5, key: 'cdFz', label: `测点分站`, checked: true },
        { index: 6, key: 'cdSensor', label: `测点传感器`, checked: true },
        { index: 7, key: 'cdBcsx1', label: `测点波长1上限`, checked: true },
        { index: 8, key: 'cdBcsx2', label: `测点波长2上限`, checked: true },
        { index: 9, key: 'cdBcsx3', label: `测点波长3上限`, checked: false },
        { index: 10, key: 'cdBcsx4', label: `测点波长4上限`, checked: false },
        { index: 11, key: 'cdBcxx1', label: `测点波长1下限`, checked: false },
        { index: 12, key: 'cdBcxx2', label: `测点波长2下限`, checked: false },
        { index: 13, key: 'cdBcxx3', label: `测点波长3下限`, checked: false },
        { index: 14, key: 'cdBcxx4', label: `测点波长4下限`, checked: false },
        { index: 15, key: 'cdBj', label: `测点报警`, checked: false },
        { index: 16, key: 'cdYj', label: `测点预警`, checked: false },
      ],
      // 数据列表
      dataList: [],
      // 总记录数
      total: 0,
      // 提交按钮是否显示
      btnSubmitVisible: true,
      // 表单校验
      rules: {
        id: [
          { required: true, message: "Id不能为空", trigger: "blur" }
        ],
      },
    };
  },
  created() {
    // 列表数据查询
    this.getList();

    var dictParams = [
    ];
  },
  methods: {
    // 查询数据
    getList() {
      this.loading = true;
      listGbPointInfo(this.queryParams).then(res => {
        if (res.code == 200) {
          this.dataList = res.data.result;
          this.total = res.data.totalNum;
          this.loading = false;
        }
      })
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 重置数据表单
    reset() {
      this.form = {
        id: undefined,
        cdLaction: undefined,
        cdBracketno: undefined,
        cdBracketname: undefined,
        cdTd: undefined,
        cdFz: undefined,
        cdSensor: undefined,
        cdBcsx1: undefined,
        cdBcsx2: undefined,
        cdBcsx3: undefined,
        cdBcsx4: undefined,
        cdBcxx1: undefined,
        cdBcxx2: undefined,
        cdBcxx3: undefined,
        cdBcxx4: undefined,
        cdBj: undefined,
        cdYj: undefined,
      };
      this.resetForm("form");
    },
    // 重置查询操作
    resetQuery() {
      this.timeRange = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length != 1
      this.multiple = !selection.length;
    },
    // 自定义排序
    sortChange(column) {
      if (column.prop == null || column.order == null) {
        this.queryParams.sort = undefined;
        this.queryParams.sortType = undefined;
      } else {
        this.queryParams.sort = column.prop;
        this.queryParams.sortType = column.order;
      }

      this.handleQuery();
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加";
      this.opertype = 1;
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const Ids = row.id || this.ids;

      this.$confirm('是否确认删除参数编号为"' + Ids + '"的数据项？')
        .then(function () {
          return delGbPointInfo(Ids);
        })
        .then(() => {
          this.handleQuery();
          this.msgSuccess("删除成功");
        })
        .catch(() => { });
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;
      getGbPointInfo(id).then((res) => {
        const { code, data } = res;
        if (code == 200) {
          this.open = true;
          this.title = "修改数据";
          this.opertype = 2;

          this.form = {
            ...data,
          };
        }
      });
    },
    /** 提交按钮 */
    submitForm: function () {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          console.log(JSON.stringify(this.form));

          if (this.form.id != undefined && this.opertype === 2) {
            updateGbPointInfo(this.form)
              .then((res) => {
                this.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              })
              .catch((err) => {
                //TODO 错误逻辑
              });
          } else {
            addGbPointInfo(this.form)
              .then((res) => {
                this.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              })
              .catch((err) => {
                //TODO 错误逻辑
              });
          }
        }
      });
    },
  },
};
</script>